package cn.z2huo.knowledge.basic.switchcontrol.newswitch;

class NewSwitch {

    public static void test(DayEnum day) {
        switch (day) {
            case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
            case TUESDAY                -> System.out.println(7);
            case THURSDAY, SATURDAY     -> System.out.println(8);
            case WEDNESDAY              -> System.out.println(9);
        }
    }

    public static void test2(DayEnum day) {
        switch (day) {
            case MONDAY, FRIDAY, SUNDAY -> {
                System.out.println(6);
            }
            case TUESDAY -> {
                // 不能引用 temp 变量
                System.out.println(7);
            }
            case THURSDAY, SATURDAY     -> System.out.println(8);
            case WEDNESDAY              -> System.out.println(9);
        }

        int result = switch (day) {
            case MONDAY, FRIDAY, SUNDAY -> {
                yield 2;
            }
            case TUESDAY -> {
                yield 3;
            }
            case THURSDAY, SATURDAY -> {
                yield 4;
            }
            case WEDNESDAY -> {
                yield 5;
            }
        };
    }

    public static int test3(DayEnum day) {
        int numLetters = switch (day) {
            case MONDAY, FRIDAY, SUNDAY -> 6;
            case TUESDAY                -> 7;
            case THURSDAY, SATURDAY     -> 8;
            case WEDNESDAY              -> 9;
        };

        int numLetters2 = switch (day) {
            case MONDAY -> 0;
            case FRIDAY -> 1;
            default -> {
                int k = day.toString().length();
                int result = k;
                yield result;
            }
        };

        return numLetters;
    }

    public static int yieldTest(DayEnum day) {
        int j = switch (day) {
            case MONDAY  -> 0;
            case TUESDAY -> {
                System.out.println("hhh");
                yield 1;
            }
            default      -> {
                String enumString = day.toString();
                yield enumString.length();
            }
        };
        return j;
    }

    public static int yieldTest2(String string) {
        int result = switch (string) {
            case "Foo":
                yield 1;
            case "Bar":
                yield 2;
            default:
                System.out.println("no Foo, no Bar");
                yield 0;
        };
        return result;
    }

    public static void returnCase(DayEnum day) {
        switch (day) {
            case MONDAY:
                return;
        }
    }

    public void continueCase(DayEnum day) {
//        for (int i = 0; i < 10; i++) {
//            int k = switch (day) {
//                case MONDAY -> 1;
//                case FRIDAY -> 2;
//                default:
//                    continue;
//            };
//        }
    }

    public static void main(String[] args) {
        System.out.println(yieldTest(DayEnum.WEDNESDAY));
    }

}